<cfparam name = "refid" default="0">
<cfparam name = "errormsg" default="">
<cfparam name = "email" default="">
<cfparam name = "password" default="">
<cfparam name = "confirmpassword" default="">
<cfparam name = "username" default="">
<cfloop from = "1" to= "#listlen(request.account_create.ffields)#" index="i">
<cfset this_field = listgetat(request.account_create.ffields, i)>
<cfif NOT this_field IS 'country'>
  <cfparam name = "#this_field#" default="">
  <cfelse>
  <cfparam name = "country" default="United States">
</cfif>
</cfloop>
<cfinvoke component="cfcs.common.shared" method="getcountries" returnvariable="qcountries" />
<cfinvoke component="cfcs.common.captcha" method="createit" returnvariable="CaptchaString" />
<cfinvoke component="cfcs.account" method="getparent" parentid="#refid#" returnvariable="qParent" />
<cfset strCaptcha = CaptchaString[1]>
<cfset captcha_check = CaptchaString[2]>
<cfif NOT isdefined('request.account_create.ffields')>
  <cfset request.account_create.ffields = "">
  <cfset request.account_create.requiredfields = "">
</cfif>

<div class="joinform">
  <form name="affilform" action="index.cfm?c=account_create&a=process" method="post" id="affilform">
    <table width="750" align="center" cellpadding="4" cellspacing="0">
      <tr>
        <td colspan="2" class="titles">New Account</td>
      </tr>
      <cfif len(trim(errormsg)) GT 0>
        <tr>
          <td colspan="2"><cfoutput>
            <div id="errorbox" style="padding: 8px;">
              <div id="errormsg">#errormsg#</div>
            </div>
            </cfoutput>
          </td>
        </tr>
      </cfif>
      <cfoutput>
      <cfif isdefined('cookie.aid')>
        <input type="hidden" name="refid" size="30" id="refid" value="#cookie.aid#" />
        <cfelse>
        <input type="hidden" name="refid" size="30" id="refid" value="0" />
      </cfif>
      </cfoutput>
      <tr>
        <td colspan="2" >&nbsp;</td>
      </tr>
      <cfif qparent.recordcount GT 0>
        <tr>
          <td class="accounts_join_label">You were referred by: </td>
          <td><cfoutput query="qParent"><strong>#qparent.firstname# #qparent.lastname#</strong></cfoutput></td>
        </tr>
      </cfif>
      <cfoutput>
      <tr>
        <td class="accounts_join_label">Email Address:</td>
        <td><input type="text" name="email" size="30" value="#email#" required="yes"></td>
      </tr>
      <tr>
        <td class="accounts_join_label">Choose a username:</td>
        <td><input type="text" name="username" id="username" value="#username#" required="yes" onchange="ColdFusion.navigate('#request.absolutepath#dialogs/accounts/checkavailable.cfm?purl='+document.getElementById('username').value, 'checkit');" />
          <a href = "javascript: ColdFusion.navigate('#request.absolutepath#dialogs/accounts/checkavailable.cfm?purl='+document.getElementById('username').value, 'checkit');">Check It</a>
          <cfdiv id="checkit"></cfdiv>
        </td>
      </tr>
      <tr>
        <td class="accounts_join_label">Choose a password:</td>
        <td><input type="password" name="password" size="25" required="yes" value="#password#" /></td>
      </tr>
      <tr>
        <td class="accounts_join_label">Retype your password: </td>
        <td><input name="confirmpassword2" size="25" type="password" value="#confirmpassword#" required="yes" /></td>
      </tr>
      <tr>
        <td class="accounts_join_label">Human Verification Code:</td>
        <td><cfimage action="captcha" width="106" height="38" text="#strCaptcha#" fontsize="26" difficulty="low" fonts="Serif.plain" color="captcha_image">
          <input type="hidden" name="captcha_check" value="#captcha_check#" /></td>
      </tr>
      <tr>
        <td class="accounts_join_label">Enter Human Verification Code Above:</td>
        <td><span class="accounts_join_captcha">
          <input type = "text" size="10" value="" name="vcode" required="yes" />
          </span></td>
      </tr>
      <cfif listlen(request.account_create.ffields) IS listlen(request.account_create.labels)>
        <cfset showlabels = 1>
        <cfelse>
        <cfset showlabels = 0>
      </cfif>
      <cfloop from = "1" to= "#listlen(request.account_create.ffields)#" index="i">
      <cfset this_field = listgetat(request.account_create.ffields, i)>
      <cfif this_field IS 'gender'>
        <tr>
          <td class="accounts_join_label"><cfif showlabels IS 1>
              #listgetat(request.account_create.labels,i)#
              <cfelse>
              #this_field#
            </cfif></td>
          <td><cfinvoke component="cfcs.common.shared" method="genderdropdown" selected="0" /></td>
        </tr>
      </cfif>
      <cfif this_field IS 'timezone_offset'>
        <tr>
          <td class="accounts_join_label"><cfif showlabels IS 1>
              #listgetat(request.account_create.labels,i)#
              <cfelse>
              #this_field#
            </cfif></td>
          <td><cfinvoke component="cfcs.common.shared" method="timezonedropdown" selected="0" /></td>
        </tr>
      </cfif>
      <cfif this_field IS 'country'>
        <cfif listcontains(request.account_create.ffields, "state", ",")>
          <cfset ocevent = "ColdFusion.navigate('#request.absolutepath#dialogs/statebox.cfm?country='+this.value+'&selectedstate=#state#', 'statediv');">
          <cfelse>
          <cfset ocevent = "">
        </cfif>
        <cfinvoke component="cfcs.common.shared" method="getcountries" returnvariable="qcountries" />
        <tr>
          <td class="accounts_join_label"><cfif showlabels IS 1>
              #listgetat(request.account_create.labels,i)#
              <cfelse>
              #this_field#
            </cfif></td>
          <td><select name = "country" id="country" onchange="#ocevent#">
              <cfloop query = "qcountries">
              <option <cfif #qcountries.country# IS #country#>SELECTED</cfif> value="#qcountries.country#">#qcountries.country#</option>
              </cfloop>
            </select>
          </td>
        </tr>
      </cfif>
      <cfif this_field IS 'state'>
        <cfset selectedstate = state>
        <tr>
          <td class="accounts_join_label"><cfif showlabels IS 1>
              #listgetat(request.account_create.labels,i)#
              <cfelse>
              #this_field#
            </cfif></td>
          <td><cfdiv id="statediv">
            <cfinclude template = "#request.absolutepath#dialogs/statebox.cfm">
            </cfdiv>
          </td>
        </tr>
      </cfif>
      <cfif NOT this_field IS 'gender' AND NOT this_field IS 'timezone_offset' AND NOT this_field IS 'country' AND NOT this_field IS 'state'>
        <tr>
          <td class="accounts_join_label"><cfif showlabels IS 1>
              #listgetat(request.account_create.labels,i)#
              <cfelse>
              #this_field#
            </cfif></td>
          <td><input type="text" value="#evaluate(this_field)#" name="#this_field#" id="#this_field#" /></td>
        </tr>
      </cfif>
      </cfloop>
      <tr>
        <td class="accounts_join_terms" colspan="2"><input type="checkbox" id="terms" name="terms" value="agree" required="Yes" message="You must read and agree to the terms and conditions before proceeding!">
          <label for="terms">I agree to the <a style="cursor: pointer;" onclick='$( "##dialog" ).dialog({autoOpen: true,modal: true,my: "center",at: "center",of: window,width: 700,height: 400});'>terms and conditions</a>.</label>
        </td>
      </tr>
      <tr>
        <td colspan="2" class="accounts_join_submit"><input type = "hidden" name="taxid" value="" />
          <input type="submit" name="SubmitButton" id="buttons" value="Create Account" />
        </td>
      </tr>
      </cfoutput>
    </table>
  </form>
</div>
<cfinclude template="../dialogs/terms.cfm">
